﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SchoolEduManage.aspx.cs" Inherits="School_Manage_SchoolEduManage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>学校统考考试管理</title>
<link href="../../Common/css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../Common/Js/jquery.js"></script>
<script type="text/javascript" src="../../Common/Js/common.js"></script>
<script type="text/javascript" src="../../Common/Js/msg.js"></script>

<script type="text/javascript">
var currSchoolYear,currTerm;
function Load()
{
    var yearObj =  document.getElementById('selYear'); 
    if(yearObj != null)
    {   
        currSchoolYear = Number("<%=currSchoolYear%>");
        for(var i = 0; i < yearObj.options.length;i++)
        {
            var option = yearObj.options[i];
           
            if(Number(option.value) == Number("<%=currSchoolYear%>"))
            {
                option.selected  = "selected";
                document.getElementById('txtYear').value = "<%=currSchoolYear%>"; 
            }
            else
                 option.selected  = false;
        }
    }
    
    var termObj =  document.getElementById('selTerm'); 
    if(termObj != null)
    {    
        currTerm = Number("<%=currTerm%>");
        for(var i = 0; i < termObj.options.length;i++)
        {
            var option = termObj.options[i];
            
            if(Number(option.value) == Number("<%=currTerm%>"))
            {
                option.selected  = "selected";
                 document.getElementById('txtTerm').value = "<%=currTerm%>";     
            }
            else
                 option.selected  = false;
        }
    }
    
  //  GetCookie();
}

//过滤学年 ---------------------------------------------------------------下拉框事件
function FilterYearChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtYear').value = value;
}
//过滤学期
function FilterTermChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtTerm').value = value;
}
//过滤年级
function FilterGradeChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtGrade').value = value;
}
//过滤状态
function FilterStateChange()
{
    var value = event.srcElement.value;
    document.getElementById('txtState').value = value;
}


//------------------------------------------------------------------------------------打开考试
function OpenSchoolExamWidow(row)
{
    var name = row.cells[0].innerText;
    var examId = row.id;
    var grade = row.cells[4].id;
    var classType = row.cells[5].id;
    var upload = false;// = row.cells[7].allowUpdate;
    
    var schoolYear = row.cells[3].schoolYear;
    var term = row.cells[3].id;
    if(schoolYear == currSchoolYear && term == currTerm)
        upload = 0;//可以上报
    else
        upload = 1;//不可以上报

    var arr = new Array();
    arr.push(examId);
    arr.push(name);
    arr.push(grade);
    arr.push(classType);
    arr.push(upload);
    
    showConfirmBox("打开考试", "确定打开此次考试?", OpenExam, arr);
}
function OpenExam(arr)
{
    var nameObj = parent.document.getElementById('txtOpenExam'); 
    if(nameObj != null)
        nameObj.innerText = "打开的考试是："+arr[1];
        
      
    SetCookie(arr[0],arr[1],arr[2],arr[3],arr[4]);
   
}


//设置cookie 保存打开的学校考试
function SetCookie(examId,examName,grade,classType,canupload)
{   
    PageMethods.SetCookie2(examId,examName,grade,classType,canupload,function(succ){
        document.getElementById('txtGrade').value = grade;
        document.getElementById('txtExamId').value = examId;
        document.getElementById('txtExamName').value = examName;
        document.getElementById('txtClassType').value = classType;
        document.getElementById('txtCanUpload').value = canupload;
        parent.canUploadScore = canupload;
        parent.isExamOpened = examId; 
        document.getElementById('btnSetCookie').click();
    },function(err){
        showMassgeBox("提示",err._message,1,null);
    });

}

////从cookie里获取打开学校考试
//function GetCookie()
//{ 
//    openedExamName = "<%=GetOpenedExamName()%>";
// 
//    var nameObj = parent.document.getElementById('txtOpenExam'); 
//    if(nameObj != null)
//    {
//        if(openedExamName.length > 0)
//            nameObj.innerText = "当前打开的考试是："+openedExamName;
//        else
//            nameObj.innerText = "当前没有打开的考试";
//    }
// 
//}



//绑定方法  --------------------------------------------------------------绑定，高亮,弹出窗口 等其他方法区域
function Bind()
{
    document.getElementById('btnBind').click();
}

function Select()
{
    document.getElementById('txtYear').value = document.getElementById('selYear').value;
    document.getElementById('txtTerm').value = document.getElementById('selTerm').value;
    document.getElementById('txtGrade').value = document.getElementById('selGrade').value;
    document.getElementById('txtState').value = -1;// document.getElementById('selState').value;
    document.getElementById('btnSelect').click();
}

//弹出成绩导入------------------------------------------------------------从其他考成绩导入
function ShowImportWindow(row)
{
    if(ValidateCurrTermYear(row))
    {
        var appluDoc = self.frames['importExamFrame'].document;
        var name = row.cells[0].innerText;
        var nameObj = appluDoc.getElementById('txtExamName');
        if(nameObj != null)
            nameObj.value = name; 
        
        var examIdObj = appluDoc.getElementById('txtExamId');
        if(examIdObj != null)
        {
            examIdObj.value = row.id;
        }
        
        var gradeObj = appluDoc.getElementById('txtGrade');
        var grade = row.cells[4].id;
        if(gradeObj != null)
        {
            gradeObj.value = grade;
        }
        
        var classTypeObj = appluDoc.getElementById('txtClassType');
        var classType = row.cells[5].id;
        if(classTypeObj != null)
        {
            classTypeObj.value = classType;
        }
        
        var bindObj = appluDoc.getElementById('btnBind');
        if(bindObj != null)
            bindObj.click();
                
        ShowPopForm("popTable", "formTitle", "导入成绩");
        showMask();
    }
    else
        showMassgeBox("提示","不能导入数据，只允许本学年本学期的考试进行导入",1,null);
}

 //关闭遮罩层
function CloseMask(formId)
{
    ClosePopForm(formId,true);
    hideMask();
}

//选中行高亮
function SetHightLight(obj)
{
    if(obj != null) 
        obj.style.backgroundColor = "#fffccf";
        
    var table = document.getElementById('schoolExamTable');
    for(var i =0 ; i < table.rows.length;i++)
    {
        var row = table.rows[i];
        if(row != null && row.rowIndex != obj.rowIndex)
        {
            row.style.backgroundColor = "#ffffff";
        }
    }
} 

//验证是否为当前学年学期
function ValidateCurrTermYear(row)
{
    var schoolYear = row.cells[3].schoolYear;
    var term = row.cells[3].id;
    if(Number(schoolYear) == Number("<%=currSchoolYear%>") && Number(term) == Number("<%=currTerm%>"))
        return true;
    else
        return false;
}


//导入数据---------------------------------------------------------------------------导入
function ShowInputWindow(row)
{
    if(ValidateCurrTermYear(row))
        showConfirmBox("提示", "是否要开此考试，并跳转到导入数据页面？", InputScore,row);
    else
        showMassgeBox("提示","不能导入数据，只允许本学年本学期的考试进行导入",1,null);
}

function InputScore(row)
{
    var name = row.cells[0].innerText;
    var examId = row.id;
    var grade = row.cells[4].id;
    var classType = row.cells[5].id;
    
    var upload ;
    var schoolYear = row.cells[3].schoolYear;
    var term = row.cells[3].id;
    if(schoolYear == currSchoolYear && term == currTerm)
        upload = 0;//可以上报
    else
        upload = 1;//不可以上报
    parent.isExamOpened = true;
        parent.canUploadScore=upload;
     PageMethods.SetCookie2(examId,name,grade,classType,upload,function(succ){
        var nameObj = parent.document.getElementById('txtOpenExam'); 
        if(nameObj != null)
            nameObj.innerText = "打开的考试是："+name;
        
        parent.canUploadScore=0;
        parent.Navigate(4,"InputScore/Left.aspx");
    },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });
}




//申报数据
function ShowUpReportWindow(row)
{
    if(ValidateCurrTermYear(row))
        showConfirmBox("申报", "确定上报此次考试?", UpReport, row.id);
    else
        showMassgeBox("提示","不能上报考试，只允许本学年本学期的考试进行上报",1,null);
}
function UpReport(examId)
{
    PageMethods.UpReportEduExam(examId,function(succ){
                if(succ > 0)
                {
                     showMassgeBox("提示","上报成功",1,null);
                     Bind();
                }
                else
                {
                     showMassgeBox("提示","上报失败，请您先倒入数据。",1,null);
                }
               
            },function(err){
                  showMassgeBox("提示",err._message,1,null);
            });
}

</script>
</head>
<body onload="Load();">
<div style="overflow-y:auto;overflow-x:none;height:98%;">
    <form id="form1" runat="server">
      <div class="mainWarp">
        <div class="pageBody" style="height:96%;" >
             <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
             </asp:ScriptManager>
             
                <ul class="butList">
                <li>
              <%--  <input type='text'  style="color:#4682B4; font-size:15px;border-right: 0px; border-top: 0px; padding-left: 0px; border-left: 0px; width: 500px; border-bottom: 0px" id="txtOpenExam" readonly/>--%>
                学年：<select id="selYear" onclick="FilterYearChange();">
                             <%= CommonScore.GetSchoolYearOption()%>
                        </select>
                         <select id="selTerm" onclick="FilterTermChange();">
                            <option value="0">全部</option>
                            <option value="1">上学期</option>
                            <option value="2">下学期</option>
                        </select>
                        年级：
                         <select id="selGrade" onclick="FilterGradeChange();">
                            <option value="-1" selected="selected">全部</option>
                                <%= CommonScore.GetGradeOption() %>
                        </select>
                         <!--状态：-->
                            <select id="selState" onclick="FilterStateChange();" style="display:none;">
                                <option value="-1" selected="selected">全部</option>
                                <option value="0">未上报</option>
                                <option value="1">已上报</option>
                            </select>
                        </li>
                        <li>
                            <input type="button" value="查询" onclick="Select();" class="commonBut" />
                        </li>
                    </ul>
             
                 <div>
                     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                         <ContentTemplate>
                                <asp:Repeater ID="Repeater1" runat="server">
                                <HeaderTemplate>
                                <div style="overflow-y:auto;overflow-x:none;height:98%;">
                                <table id="schoolExamTable" class="useList" style="width: 95%">
                                    <tr>
                                        <th style="text-align: left;padding-left: 5px;">考试名</th>
                                        <th style="text-align: left;padding-left: 5px;display:none;">状态</th>
                                        <th style="text-align: left;padding-left: 5px;">创建时间</th>
                                        <th style="text-align: left;padding-left: 5px;">学年学期</th>
                                        <th style="text-align: left;padding-left: 5px;">年级</th>
                                        <th style="text-align: left;padding-left: 5px;">分科</th>
                                        <th>打开考试</th>
                                        <th>从学校考试导入</th>
                                        <th>成绩录入</th>
                                        <th style=" display:none;">成绩上报</th>
                                    </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr id="<%# Eval("RID") %>" style="background-color:<%#CommonScore.GetOpenExamColor(1,currentOpenEXAM,SchoolCookie.ExamType,(int)Eval("RID")) %>">
                                        <td style="text-align: left;padding-left: 5px;"><%# Eval("Name") %></td>
                                        <td style="display:none;text-align: left;padding-left: 5px;color:<%# GetStateColor((int)Eval("Status")) %>"><%# ConvertState((int)Eval("Status"))%></td>
                                        <td style="text-align: left;padding-left: 5px;"><%# ((DateTime)Eval("CreateDate")).ToShortDateString()%></td>
                                        <td style="text-align: left;padding-left: 5px;" schoolYear="<%# Eval("SchoolYear") %>" id="<%# Eval("Term")%>"><%# Eval("SchoolYear") %><%# ConvertTerm((short)Eval("Term"))%></td>
                                        <td id="<%# Eval("Grade")%>" style="text-align: left;padding-left: 5px;"><%# ConvertGrade((int)Eval("Grade"))%></td>
                                        <td id="<%# Eval("ClassType")%>" style="text-align: left;padding-left: 5px;"><%# ConvertClassType((int)Eval("ClassType"))%></td>
                                        <td><a><img src="<%# CommonScore.OpenExamSrc(1,SchoolCookie.ExamType,currentOpenEXAM,(int)Eval("RID")) %>" alt="打开考试" class="imageBtnStyle" onclick="if(parent.report  || parent.edumanage){OpenSchoolExamWidow(this.parentElement.parentElement.parentElement);}else{showMassgeBox('提示','您没有权限使用这个功能！',1,null);}" /></a></td>
                                        <td allowUpdate="<%# Eval("Status") %>"><a><img src="../../Common/images/imputlogo.png" alt="从学校考试导入" class="imageBtnStyle"  allowUpdate="<%# Eval("Status") %>" onclick="if(parent.edumanage){ShowImportWindow(this.parentElement.parentElement.parentElement)}" /></a> </td>
                                        <td><a><img src="../../Common/images/import1.png" alt="成绩录入" class="imageBtnStyle" allowUpdate="<%# Eval("Status") %>" onclick="if(parent.edumanage){ShowInputWindow(this.parentElement.parentElement.parentElement);}" /></a></td>
                                        <td style=" display:none;"><a><img src="../../Common/images/applyExam1.png" alt="申报" class="imageBtnStyle" onclick="if(parent.edumanage){ShowUpReportWindow(this.parentElement.parentElement.parentElement);}"/></a>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </table></div>
                                </FooterTemplate>
                               </asp:Repeater> 
                         </ContentTemplate>
                         <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
                            <asp:AsyncPostBackTrigger ControlID="btnSetCookie" EventName="Click" />
                            <asp:AsyncPostBackTrigger ControlID="btnSelect" EventName="Click" />
                         </Triggers>
                     </asp:UpdatePanel>
                     <div style="display: none;">
                        <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
                        <asp:Button ID="btnSelect" runat="server"   Text="查询" OnClick="btnSelect_Click" /> 
                        <asp:Button ID="btnSetCookie" runat="server" Text="btnSetCookie" OnClick="btnSetCookie_Click" />
                        <asp:TextBox ID="txtYear" runat="server" />
                        <asp:TextBox ID="txtTerm" runat="server" />
                        <asp:TextBox ID="txtGrade" runat="server" />
                        <asp:TextBox ID="txtState" runat="server" />
                        <asp:TextBox ID="txtExamId" runat="server" />
                        <asp:TextBox ID="txtExamName" runat="server" />
                        <asp:TextBox ID="txtClassType" runat="server" />
                        <asp:TextBox ID="txtCanUpload" runat="server" />
                     </div>
                     
                      <%-- 从其他考试导入弹出层 --%>
                    <div id="popTable" class="layoutWarp" style="display: none; width: 400px; height=130px;overflow: inherit;">
                        <div class="title">
                            <span id="formTitle">从其他考试导入</span> <a title="关闭" onclick="return CloseMask('popTable')">
                                关闭</a>
                        </div>
                         <iframe id="importExamFrame" width="100%" height="120px" src="InputScore/InputExam.aspx" frameborder="0"></iframe>     
                     </div>
                     
                 </div>
            </div>
          </div>
    </form>
    </div>
</body>
</html>
